package com.xxh.chatdemo.destroy;

import com.xxh.chatdemo.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 服务销毁时调用,销毁用户信息
 */
@Component
@Slf4j
public class DestroyEvent implements DisposableBean {

    @Autowired
    RedisUtil redisUtil;
    @Override
    public void destroy() throws Exception {
        Set<String> keys = redisUtil.keys("user*");
        redisUtil.delete(keys);
        log.info("删除完成");
    }
}
